home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / PICTWIND.PAK / PICTWINX.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  118 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (C) 1995, 1995 by Borland International, All Rights Reserved
  4. //
  5. //----------------------------------------------------------------------------
  6. #include <owl/pch.h>
  7. #include <owl/applicat.h>
  8. #include <owl/framewin.h>
  9. #include <owl/gdiobjec.h>
  10. #include <owl/pictwind.h>
  11. #include "pictwind.rh"
  12.  
  13. const char* Picture = "sample.bmp";
  14.  
  15. //
  16. // class TSampleApp
  17. // ~~~~~ ~~~~~~~~~~
  18. class TSampleApp : public TApplication {
  19.   public:
  20.     TSampleApp()
  21.     {
  22.       CurrentHow = TPictureWindow::Center;
  23.     }
  24.  
  25.     void InitMainWindow();
  26.  
  27.     void CmCenter()
  28.     {
  29.       CurrentHow = TPictureWindow::Center;
  30.       NewClient(TPictureWindow::Center);
  31.     }
  32.     void CeCenter(TCommandEnabler& ce);
  33.  
  34.     void CmUpperLeft()
  35.     {
  36.       CurrentHow = TPictureWindow::UpperLeft;
  37.       NewClient(TPictureWindow::UpperLeft);
  38.     }
  39.     void CeUpperLeft(TCommandEnabler& ce);
  40.  
  41.     void CmStretch()
  42.     {
  43.       CurrentHow = TPictureWindow::Stretch;
  44.       NewClient(TPictureWindow::Stretch);
  45.     }
  46.     void CeStretch(TCommandEnabler& ce);
  47.  
  48.     void NewClient(TPictureWindow::TDisplayHow how);
  49.  
  50.   private:
  51.     TPictureWindow::TDisplayHow CurrentHow;
  52.  
  53.   DECLARE_RESPONSE_TABLE(TSampleApp);
  54. };
  55.  
  56. void
  57. TSampleApp::CeCenter(TCommandEnabler& ce)
  58. {
  59.   ce.SetCheck(CurrentHow == TPictureWindow::Center?
  60.               TCommandEnabler::Checked :
  61.               TCommandEnabler::Unchecked);
  62. }
  63.  
  64. void
  65. TSampleApp::CeUpperLeft(TCommandEnabler& ce)
  66. {
  67.   ce.SetCheck(CurrentHow == TPictureWindow::UpperLeft ?
  68.               TCommandEnabler::Checked :
  69.               TCommandEnabler::Unchecked);
  70. }
  71.  
  72. void
  73. TSampleApp::CeStretch(TCommandEnabler& ce)
  74. {
  75.   ce.SetCheck(CurrentHow == TPictureWindow::Stretch ?
  76.               TCommandEnabler::Checked :
  77.               TCommandEnabler::Unchecked);
  78. }
  79.  
  80.  
  81. DEFINE_RESPONSE_TABLE1(TSampleApp, TApplication)
  82.   EV_COMMAND       (CM_CENTER,    CmCenter),
  83.   EV_COMMAND_ENABLE(CM_CENTER,    CeCenter),
  84.   EV_COMMAND       (CM_UPPERLEFT, CmUpperLeft),
  85.   EV_COMMAND_ENABLE(CM_UPPERLEFT, CeUpperLeft),
  86.   EV_COMMAND       (CM_STRETCH,   CmStretch),
  87.   EV_COMMAND_ENABLE(CM_STRETCH,   CeStretch),
  88. END_RESPONSE_TABLE;
  89.  
  90. void
  91. TSampleApp::NewClient(TPictureWindow::TDisplayHow how)
  92. {
  93.   TWindow* cw = new TPictureWindow(0, new TDib(Picture), how);
  94.   cw->Attr.ExStyle |= WS_EX_CLIENTEDGE;
  95.  
  96.   TWindow* oldClient = GetMainWindow()->SetClientWindow(cw);
  97.  
  98.   delete oldClient;
  99. }
  100.  
  101. void
  102. TSampleApp::InitMainWindow()
  103. {
  104.   TWindow* cw = new TPictureWindow(0, new TDib(Picture), TPictureWindow::Center);
  105.   cw->Attr.ExStyle |= WS_EX_CLIENTEDGE;
  106.  
  107.   // create main window
  108.   //
  109.   SetMainWindow(new TFrameWindow(0, "Picture Window", cw));
  110.   GetMainWindow()->AssignMenu(IDM_MAINMENU);
  111. }
  112.  
  113. int
  114. OwlMain(int /*argc*/, char* /*argv*/[])
  115. {
  116.   return TSampleApp().Run();
  117. }
  118.